<?php
	session_start();
	require('Games/game_functions.php');
	
	$game = $_POST['game'];
	$vote = $_POST['vote'];
	
	if($vote == '+'){
		$vote = 'Y';
	}else if($vote == '-'){
		$vote = 'N';
	}else if($vote != ''){
		$vote = '?';
	}
	
	
if($game != ''){
dblogin();
	/* check to see if that player has a vote there, and if so, update else insert*/
	$query = "select g.gameid from GAME_VOTE g where g.gameid = '$game' and g.player = {$_SESSION['USERNUM']}";
	$result = mysql_query($query);
	if($row = mysql_fetch_array($result)){
		/* update */
		$query = "update GAME_VOTE g  set vote = '$vote' where g.gameid = '$game' and player = {$_SESSION['USERNUM']};";
		$result = mysql_query($query);
		$query = "update GAME_VOTE g  set sub_dt = now() where g.gameid = '$game' and player = {$_SESSION['USERNUM']};";
		$result = mysql_query($query);
	}else{
		/* insert */
		$query = "insert into GAME_VOTE values ($game, {$_SESSION['USERNUM']},'$vote',now());";
		$result = mysql_query($query);
	}
}
	
?>

<script type="text/javascript">
$(document).ready(function(){

	$("#gamelist_ajax").load("Games/games.php",{type:'UNVOTE'});
/*	$("#game_cont > ul").tabs();*/
	$(".tabtitle").click(function(){
		$("#gamelist_ajax").load("Games/games.php",{type:$(this).attr("name")}).fadeIn("slow");
		return false;
	});

	$("#add_button").click(function(){	
		$("#add_ajax").load("Games/game_add.php").fadeIn("slow");
		/*$("#add_ajax").fadeIn("slow");*/
		
	});	
});
</script>


<div id="game_cont">
	<div id="tabs">
		<ul class="ui-tabs-nav" style="height: 30px;">
			<li class="ui-tabs-nav-item"><a href="#" class="tabtitle" name="UNVOTE">Unvoted</a></li>
			<li class="ui-tabs-nav-item"><a href="#" class="tabtitle" name="PEND">Pending</a></li>
			<li class="ui-tabs-nav-item"><a href="#" class="tabtitle" name="PLAY">Playable</a></li>
			<li class="ui-tabs-nav-item"><a href="#" class="tabtitle" name="DONE">Played</a></li>
			<li class="ui-tabs-nav-item"><a href="#" class="tabtitle" name="ALL">All Games</a></li>
			<li class="ui-tabs-nav-item"><a href="#" class="tabtitle" name="ME">My Games</a></li>
		</ul>
	</div>
	<div id="gamelist_ajax" class="ui-tabs-panel">
	</div>
</div>

<div id="add_game">
<img class="pointer" src="images/icons/add_game.png" id="add_button" />
	<div id="add_ajax">
	</div>
</div>
